package Protocoltcp;/*

 */

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.CharsetUtil;

/**
 * @ClassName MyClientHandler
 * @Author Final
 * @Project DataStructures
 */
public class MyClientHandler extends SimpleChannelInboundHandler<MessageProtocol> {



    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        for (int i=0;i<10;i++){

            String msg="好热，我要脱衣服";

            byte[] bytes = msg.getBytes(CharsetUtil.UTF_8);

            int length =msg.getBytes(CharsetUtil.UTF_8).length;

            //创建协议包对象
            MessageProtocol messageProtocol = new MessageProtocol();
            messageProtocol.setLen(length);
            messageProtocol.setContent(bytes);
            ctx.writeAndFlush(messageProtocol);
        }



    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MessageProtocol byteBuf) throws Exception {

    }
}
